﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Marmat.Template.WinForm;
using Marmat.FrameWork;

namespace 测试项目.TestDemo
{
    class TestFirstDemoCommand : IDocumentCommandPagination<TestDemoEntity>, IDocumentCommandObjectConversionProvider, IAdvRelationProvider<TestDemoEntity>
    {

        public string Name => throw new NotImplementedException();

        public string PrimaryName => nameof(TestDemoEntity.Name);

        public string DisplayName => nameof(TestDemoEntity.Name);

        public object Create(TestDemoEntity item)
        {
            return 1;
        }

        public void Delete(TestDemoEntity item)
        {
            throw new NotImplementedException();
        }

        public ObjectConversion GetConversion()
        {
            ObjectConversion conversion = new ObjectConversion();
            conversion.Register<TestDemoEntity>(x => x.Name).Serialize(x => new { x.Arg, x.Name });
            return conversion;
        }

        public TestDemoEntity[] Load(string condition, int page, int top, string order, out int count)
        {
            count = 100;
            List<TestDemoEntity> items = new List<TestDemoEntity>();
            for (int i = 0; i < count; i++)
            {
                items.Add(new TestDemoEntity() { Name = i.ToString() });
            }
            return items.ToArray();
        }

        public TestDemoEntity Load(object id)
        {
            return new TestDemoEntity();
        }

        public TestDemoEntity[] Load(IEnumerable<object> ids)
        {
            int count = 100;
            List<TestDemoEntity> items = new List<TestDemoEntity>();
            for (int i = 0; i < count; i++)
            {
                items.Add(new TestDemoEntity() { Name = i.ToString() });
            }
            return items.ToArray();
        }

        public void Write(TestDemoEntity item)
        {
            var dic = this.ToDictionary(item);
        }
    }
}